package com.hrw.musicplayer.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hrw.musicplayer.R;

public class MusicAdapter extends BaseAdapter {

	// private Bitmap down_icon;
	// private Bitmap up_icon;
	// private Bitmap suspend_icon;
	// private Bitmap play_icon;
	private Bitmap music_file;
	private List<String> list;
	LayoutInflater inflater;

	public MusicAdapter(Context context, List<String> list) {
		this.list = list;
		inflater = LayoutInflater.from(context);
		music_file = BitmapFactory.decodeResource(context.getResources(),
				R.drawable.itunes2);
	}

	@Override
	public int getCount() {

		return list.size();
	}

	@Override
	public Object getItem(int position) {

		return list.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.file_row, null);

			// Creates a ViewHolder and store references to the two children
			// views
			// we want to bind data to.
			holder = new ViewHolder();
			holder.text = (TextView) convertView.findViewById(R.id.text);
			holder.icon = (ImageView) convertView.findViewById(R.id.image_Icon);
			holder.icon.setImageBitmap(music_file);
			convertView.setTag(holder);
		} else {
			// Get the ViewHolder back to get fast access to the TextView
			// and the ImageView.
			holder = (ViewHolder) convertView.getTag();
		}
		holder.text.setText(list.get(position));
		convertView.setTag(holder);
		return convertView;
	}

	static class ViewHolder {
		private TextView text;
		private ImageView icon;
	}

}
